<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib prefix='c' uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
	function change(value){
		 if(value=="1"){
			 form1.discount.disabled="disabled";
			 form1.promotionprice.disabled="disabled";
			 form1.promotionnum.disabled="disabled";
			 
			 
		 }else if(value=="2"){
			 form1.discount.disabled="";
			 form1.promotionprice.disabled="disabled";
			 form1.promotionnum.disabled="disabled";
		 }else if(value=="3"){
			 form1.discount.disabled="disabled";
			 form1.promotionprice.disabled="";
			 form1.promotionnum.disabled="";
		 }
		 
	 }
	function getSum(){
		
		if(document.getElementById("zero").value=="1"){
			if(document.getElementById("zero1")!=null&&document.getElementById("zero2")!=null){
				
				document.getElementById("sum").value=document.getElementById("zero1").value*document.getElementById("zero2").value;
				
			}
			
			
		}else if(document.getElementById("zero").value=="2"){
	
			if(document.getElementById("zero1")!=null&&document.getElementById("zero2")!=null&&document.getElementById("one")!=null){
				document.getElementById("sum").value=document.getElementById("zero1").value*document.getElementById("zero2").value
				*document.getElementById("one").value;
			}
			
			
		}else if(document.getElementById("zero").value=="3"){
	
			if(document.getElementById("zero1")!=null&&document.getElementById("zero2")!=null&&document.getElementById("two")!=null&&document.getElementById("three")!=null){
				document.getElementById("sum").value=(document.getElementById("zero1").value-document.getElementById("three").value)*document.getElementById("zero2").value+
				document.getElementById("three").value*document.getElementById("two").value;

			}
			
		}
		
	}
</script>
</head>
<body>
<h2>增加订单明细</h2>
<form action="<%=request.getContextPath()%>/servlet/itemsservlet?method=add&orderid=<%=request.getParameter("orderid") %>" method="post" name='form1'>
 <table border='1'>
 <tr>
  <td colspan='2'>订单id=<%=request.getParameter("orderid") %></td>
 </tr>
 <tr>
  <td>货物名称<input type="text" name="itemname"></td>
  <td>折扣类型
   <select name="discounttype" onchange="change(this.value)" id="zero">
    <option value="1">normal</option>
    <option value="2">discount</option>
    <option value="3">promotion</option>
   </select>
  </td>
 </tr>
 <tr>
   <td>货物数量<input type='text' name='unitnum' id="zero1"></td>
   <td>货物单价<input type="text" name="unitprice" id="zero2"></td>
 </tr>
 <tr>
  <td>货物总价<input type="text" name="sum" onfocus="getSum()" id="sum"/></td>
  <td>折扣率<input type="text" name="discount" disabled="disabled" id="one"></td>
 </tr>
 <tr>
   <td>促销单价<input type="text" name="promotionprice" disabled="disabled" id="two"></td>
   <td>促销数量<input type="text" name="promotionnum" disabled="disabled" id="three"></td>
 </tr>
</table>
 <input type="submit" value="新增">
 
 
</form>
<br/>
 <input type="submit" onclick="document.location.href='<%=request.getContextPath() %>/servlet/itemsservlet?method=list&orderid=<%=request.getParameter("orderid") %>'" value="返回">

</body>
</html></html>